﻿using Modules.Constructor;
using PetaPoco;
using PmSoft;
using PmSoft.Caching;
using PmSoft.Entity;
using System.ComponentModel;

namespace Modules.Corp
{
    /// <summary>
    /// 施工总包、劳务分包、专业分包、监理企业信息表
    ///</summary>
    [TableName("corp")]
    [Description("施工总包,劳务分包,专业分包,监理企业信息")]
    [PrimaryKey("corp_id", AutoIncrement = true)]
    [CacheSetting(true, PropertyNamesOfArea = "ProjectId")]
    [Serializable]
    public class CorpInfo : IDelEntity, IProjectUser
    {
        /// <summary>
        /// (企业ID)主键
        ///</summary>
        [Column("corp_id")]
        public int CorpId { get; set; }

        /// <summary>
        /// 企业名称
        ///</summary>
        [Column("name")]
        public string Name { get; set; }

        /// <summary>
        /// 企业信用代码
        ///</summary>
        [Column("code")]
        public string Code { get; set; }

        /// <summary>
        /// 企业分类
        /// </summary>
        [Column("corp_type")]
        public 企业分类? CorpType { get; set; }

        /// <summary>
        /// 安全信息ID
        /// 默认值: 0
        ///</summary>
        [Column("security_id")]
        public int SecurityId { get; set; }

        /// <summary>
        /// 归属省
        ///</summary>
        [Column("province_code")]
        public int ProvinceCode { get; set; }

        /// <summary>
        /// 归属地市
        ///</summary>
        [Column("city_code")]
        public int CityCode { get; set; }

        /// <summary>
        /// 归属区县
        ///</summary>
        [Column("area_code")]
        public int AreaCode { get; set; }

        /// <summary>
        /// 注册地址
        ///</summary>
        [Column("reg_addr")]
        public string RegAddr { get; set; }

        /// <summary>
        /// 办公地址
        ///</summary>
        [Column("office_addr")]
        public string OfficeAddr { get; set; }

        /// <summary>
        /// 法人姓名
        ///</summary>
        [Column("legalman")]
        public string Legalman { get; set; }

        /// <summary>
        /// 法人身份证号码
        ///</summary>
        [Column("legal_cardno")]
        public string LegalCardno { get; set; }

        /// <summary>
        /// 法人手机号码
        ///</summary>
        [Column("legal_mobile")]
        public string LegalMobile { get; set; }

        /// <summary>
        /// 法人职务
        ///</summary>
        [Column("legal_duty")]
        public string LegalDuty { get; set; }

        /// <summary>
        /// 法人职称
        ///</summary>
        [Column("legal_title")]
        public string LegalTitle { get; set; }

        /// <summary>
        /// 经济类型
        ///</summary>
        [Column("economic_type")]
        public CorpEconomicType EconomicType { get; set; }

        /// <summary>
        /// 企业单位类型
        /// </summary>
        [Column("type")]
        public ConstructorType Type { get; set; }

        /// <summary>
        /// 邮编
        ///</summary>
        [Column("zip_code")]
        public string ZipCode { get; set; }

        /// <summary>
        /// 注册资本
        ///</summary>
        [Column("reg_capital")]
        public decimal? RegCapital { get; set; }

        /// <summary>
        /// 企业注册日期
        ///</summary>
        [Column("register_date")]
        public DateTime RegisterDate { get; set; }

        /// <summary>
        /// 联系人
        ///</summary>
        [Column("link_man")]
        public string LinkMan { get; set; }

        /// <summary>
        /// 联系人电话
        ///</summary>
        [Column("link_tel")]
        public string LinkTel { get; set; }

        /// <summary>
        /// 企业备注
        ///</summary>
        [Column("remark")]
        public string Remark { get; set; }

        /// <summary>
        /// 创建时间
        ///</summary>
        [Column("create_time")]
        public DateTime? CreateTime { get; set; } = DateTime.Now;

        /// <summary>
        /// 默认项目ID
        /// </summary>
        [Column("project_id")]
        public int ProjectId { get; set; }

        /// <summary>
        /// 数据来源 (1:手动新增 2:平台导入)
        /// </summary>
        [Column("data_source")]
        public DataSource? DataSource { get; set; }

        /// <summary>
        /// 是否已认证
        /// </summary>
        [Column("has_auth")]
        public bool HasAuth { get; set; }

        /// <summary>
        /// 审核状态 0：待审核 1：审核通过 -1：审核失败
        /// </summary>
        [Column("check_status")]
        public 审核状态 CheckStatus { get; set; }

        /// <summary>
        /// 审核失败原因
        /// </summary>
        [Column("failure_reason")]
        public string FailureReason { get; set; } = string.Empty;

        /// <summary>
        /// 是否已删除
        /// </summary>
        [Column("is_deleted")]
        public bool IsDeleted { get; set; }

        #region IDelEntity 成员

        [Ignore]
        object IEntity.EntityId { get { return this.CorpId; } }

        [Ignore]
        bool IDelEntity.IsDeletedInDatabase { get => this.IsDeleted; set => this.IsDeleted = value; }


        #endregion IEntity 成员

        #region IUser

        [Ignore]
        string IUser.Name => this.Name;

        [Ignore]
        int IUser.Id => this.CorpId;

        [Ignore]
        UserType IUser.Type => UserType.Corp;

        [Ignore]
        int? IProjectUser.ProjectId => this.ProjectId;


        #endregion IUser
    }
}